package com.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.game.pojo.po.User;
import com.game.dao.UserDao;
import com.game.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lvhao
 * @since 2020-07-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User login(String username, String password) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("password",password);
        queryWrapper.eq("username",username);
        if(userDao.selectOne(queryWrapper) != null){
            User user = userDao.selectOne(queryWrapper);
            user.setLoginTime(LocalDateTime.now().toString());
            /*
            登陆成功，记录时间
             */
            userDao.updateById(user);
            return user;
        }
        return null;
    }
}
